﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MockPrjTeam2.Biz;
using MockPrjTeam2.Entity;

namespace MockPrjTeam2.Pages.Forms
{
    public partial class AddTrustDistrict : System.Web.UI.Page
    {
        private int trustDistrictId;
        private TrustDistrictBiz biz;
        private TrustRegion _trustRegion = new TrustRegion();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                TxtTrustRegionName.Text = Session["TrustRegionName"].ToString();
            }

        }
        public int CheckTrustDistrictNameExist(string trustDistrictName)
        {
            TrustDistrictBiz trustDistrictBiz = new TrustDistrictBiz();
            return trustDistrictBiz.CheckTrustDistrictNameExist(trustDistrictName);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            TrustDistrictBiz biz = new TrustDistrictBiz();
            TrustDistrict trustDistrict = new TrustDistrict();
            int checkTrustDistrictName = CheckTrustDistrictNameExist(TxtTrustDistrictName.Text);
            if (checkTrustDistrictName > 0)
            {
                lblCheckTrustDistrictName.Text = "Trust District Name does exist ! Please new Trust District Name !";
                return;
            }
            trustDistrict.TrustDistrictName = TxtTrustDistrictName.Text;
            trustDistrict.DescriptionDistrict = TxtDescription.Text;
            trustDistrict.TrustRegionID = Convert.ToInt32(Session["TrustRegionID"]);
            
            bool result = biz.AddTrustDistrict(trustDistrict);
            if (result == true)
            {
                if (Session.Contents["TrustRegionName"] != null)
                {
                    Session["TrustRegionName"] = null;
                }
                if (Session.Contents["TrustRegionID"] != null)
                {
                    Session["TrustRegionID"] = null;
                }
                Response.Redirect("../Forms/TrustRegionDetails.aspx");
            }
        }

        
    }
}